<template>
    <div class="container">
        
        <h3>{{ info.title }}</h3>
        <p>
            <span>发表时间：{{ info.add_time | dateFormat }}</span>
            <span>点击：{{ info.click }}次</span>            
        </p>
        <hr>

        <!-- 缩略图区域 -->
        <div class="thumbs">
            <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open(index, list)" :key="item.src">
        </div>

        <div v-html="info.content" class="content"></div>

        <!-- 评论组件  此处的id为图片id-->
        <comment-box :id="id"></comment-box> 
    </div>
</template>

<script>
//导入评论组件
import comment from '../subComponent/comment.vue';

    export default {
        data() {
            return {
               id: this.$route.params.id,  //要查看的图片的id
               info: {},  //图片详情
               list:[]     //缩略图
            }
        },
        created () {
            this.getImageInfo();
            this.getImageList();
        },
        methods: {
            //获取图片详情
            getImageInfo() {
                this.$http.get("api/getimageInfo/"+ this.id).then(result=>{
                    if(result.body.status === 0) {
                        this.info = result.body.message[0];
                    }
                })
            },
            getImageList() {
                this.$http.get("api/getthumimages/" + this.id).then(result=> {
                    if(result.body.status === 0) {
                        //将每一张的图片补充完整
                        result.body.message.forEach(item=>{
                            item.w = 600;
                            item.h = 400;
                        });

                        this.list = result.body.message;
                    }
                })
            }
        },
        components: {
            "comment-box": comment
        }
    }

</script>

<style lang="scss" scoped>
.container {
    padding: 5px;
    h3 {
        font-size: 18px;
        color: blue;
        text-align: center;
    }
    p {
        display: flex;
        justify-content: space-between;
        line-height: 40px;
    }
    .thumbs {
        img {
            margin: 10px;
            box-shadow: 0 0 6px #888;
        }
    }
    .content {
        font-size: 14px;
        line-height: 30px;
    }
}
</style>
